import 'package:flutter/material.dart';

/// 申请权限弹窗 布局如下
/// ===================
///       title
///       content
///   buttonLeft buttonRight
/// ===================
class ApplyPermissionDialog extends StatelessWidget {
  /// 标题
  final String title;
  final String desc;

  /// 原dialog对应参数
  final EdgeInsetsGeometry titlePadding;
  final EdgeInsetsGeometry contentPadding;
  final EdgeInsets insetPadding;

  /// 白色容器对应的radius
  final double containerRadius;

  /// 左右按钮的文字
  final String leftButtonName;
  final String rightButtonName;

  final TextStyle titleTextStyle;
  final TextStyle contentTextStyle;

  final Color rightBtnBg;
  final Color leftBtnBg;

  /// 左右文字的样式
  final TextStyle leftTextStyle;
  final TextStyle rightTextStyle;

  /// 左右按钮的点击事件
  final VoidCallback? onLeftButtonClickListener;
  final VoidCallback? onRightButtonClickListener;

  ApplyPermissionDialog({
    Key? key,
    this.title = "权限申请",
    required this.desc,
    this.titlePadding = const EdgeInsets.fromLTRB(20.0, 16.0, 16.0, 0),
    this.contentPadding = const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 16),
    this.insetPadding = const EdgeInsets.symmetric(horizontal: 45.0, vertical: 24.0),
    this.containerRadius = 5.0,
    this.leftButtonName = "拒绝",
    this.rightButtonName = "下一步",
    this.onLeftButtonClickListener,
    this.onRightButtonClickListener,
    this.rightBtnBg = const Color(0xFFF9DF52),
    this.leftBtnBg = const Color(0xFFEDEDED),
    this.titleTextStyle = const TextStyle(fontSize: 17, color: Color(0xFF3A3C41), fontWeight: FontWeight.bold),
    this.leftTextStyle = const TextStyle(fontSize: 14, color: Color(0xFF222222), fontWeight: FontWeight.normal),
    this.contentTextStyle = const TextStyle(fontSize: 14, color: Color(0xFF3A3C41), fontWeight: FontWeight.normal),
    this.rightTextStyle = const TextStyle(fontSize: 14, color: Color(0xFF222222), fontWeight: FontWeight.normal),
  }) : super(key: key);

  /// 构建按钮组
  List<Widget> get _buildButtonGroup {
    return [
      Padding(
        padding: const EdgeInsets.only(bottom: 20),
        child: Text(desc, style: contentTextStyle),
      ),
      SizedBox(
        height: 40,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Expanded(
              child: GestureDetector(
                onTap: onLeftButtonClickListener,
                child: Container(
                  width: double.infinity,
                  height: double.infinity,
                  decoration: BoxDecoration(
                    color: leftBtnBg,
                    borderRadius: BorderRadius.circular(20),
                  ),
                  alignment: Alignment.center,
                  child: Text(leftButtonName, style: leftTextStyle),
                ),
              ),
            ),
            const SizedBox(width: 16, height: 1),
            Expanded(
              child: GestureDetector(
                onTap: onRightButtonClickListener,
                child: Container(
                  width: double.infinity,
                  height: double.infinity,
                  decoration: BoxDecoration(
                    color: rightBtnBg,
                    borderRadius: BorderRadius.circular(20),
                  ),
                  alignment: Alignment.center,
                  child: Text(rightButtonName, style: rightTextStyle),
                ),
              ),
            ),
          ],
        ),
      ),
    ];
  }

  @override
  Widget build(BuildContext context) {
    return SimpleDialog(
      titlePadding: titlePadding,
      contentPadding: contentPadding,
      insetPadding: insetPadding,
      title: Text(title, textAlign: TextAlign.center),
      titleTextStyle: titleTextStyle,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(containerRadius))),
      children: _buildButtonGroup,
    );
  }
}
